from pydantic import BaseModel


class HTTPApiResponse(BaseModel):
    code: int
    msg: str
    data: dict | list | str | int | None = None

    @classmethod
    def success(cls, data):
        return cls(code=0, msg="success", data=data)

    @classmethod
    def failed(cls, code, msg):
        if code == 0:
            raise ValueError("失败state值不可以等于0")
        return cls(code=code, msg=msg)
